<template>
  <el-container class="home_con">
    <!-- 头部区域 -->
    <el-header>
      <span @click="getWelcom">电商管理系统</span>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px">
        <el-menu
          background-color="#73798d"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          router
          :default-active="localPath"
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in menuList"
            :key="item.id"
          >
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item
              :index="'/' + item2.path"
              v-for="item2 in item.children"
              :key="item2.id"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ item2.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体区域 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      menuList: [],
      localPath: '',
    }
  },
  created() {
    this.getList()
  },
  updated() {
    this.getPaths()
  },
  methods: {
    async getList() {
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status === 200) {
        this.menuList = res.data
      }
    },
    getPaths() {
      if (this.$route.path === '/home' || this.$route.path === '/home/welcome')
        return (this.localPath = '')
      this.localPath = this.$route.path
      console.log(this.localPath)
    },
    getWelcom() {
      this.$router.push('/home')
    },
  },
}
</script>

<style lang="less" scoped>
.home_con {
  height: 100%;
}
.el-header {
  background-color: #b3c0d1;
  line-height: 60px;
  font-size: 30px;
  font-weight: 600;
  color: #fff;
  text-align: center;
  span {
    text-shadow: 0 0 17px #fff;
    cursor: pointer;
  }
}
.el-aside {
  background-color: #73798d;

  .el-menu {
    border-right: none;
  }
}
.el-main {
  background-color: #e9eef3;
}
</style>